<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>This factory method creates a hash from a file</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="quickhashintstringhash.getsize.html">« QuickHashIntStringHash::getSize</a></li>
      <li style="float: right;"><a href="quickhashintstringhash.loadfromstring.html">QuickHashIntStringHash::loadFromString »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.quickhashintstringhash.html">QuickHashIntStringHash</a></li>
    <li>This factory method creates a hash from a file</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="quickhashintstringhash.loadfromfile" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">QuickHashIntStringHash::loadFromFile</h1>
  <p class="verinfo">(PECL quickhash &gt;= Unknown)</p><p class="refpurpose"><span class="refname">QuickHashIntStringHash::loadFromFile</span> &mdash; <span class="dc-title">This factory method creates a hash from a file</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-quickhashintstringhash.loadfromfile-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><strong>QuickHashIntStringHash::loadFromFile</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$size</code><span class="initializer"> = 0</span></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>): <span class="type"><a href="class.quickhashintstringhash.html" class="type QuickHashIntStringHash">QuickHashIntStringHash</a></span></div>

  <p class="para rdfs-comment">
   This factory method creates a new hash from a definition file on disk. The
   file format consists of a signature <code class="literal">&#039;QH\0x12\0&#039;</code>, the number of elements as
   a 32 bit signed integer in system Endianness, an unsigned 32 bit integer
   containing the number of element data to follow in characters. This element
   data contains all the strings. After the header and the strings, the
   elements follow in pairs of two unsigned 32 bit integers where the first
   one is the key, and the second one the index in the element data
   string. An example could be:
  </p>
  <p class="para">
   <div class="example" id="example-5137">
    <p><strong>示例 #1 QuickHash IntString file format</strong></p>
    <div class="example-contents screen"><div class="cdata"><pre>00000000  51 48 12 00 02 00 00 00  09 00 00 00 4f 4e 45 00  |QH..........ONE.|
00000010  4e 49 4e 45 00 01 00 00  00 00 00 00 00 03 00 00  |NINE............|
00000020  00 04 00 00 00                                    |.....|
00000025
</pre></div></div>
   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5138">
    <p><strong>示例 #2 QuickHash IntString file format</strong></p>
    <div class="example-contents screen"><div class="cdata"><pre>
header signature (&#039;QH&#039;; key type: 1; value type: 2; filler: \0x00)
00000000  51 48 12 00

number of elements:
00000004  02 00 00 00

length of string values (9 characters):
00000008  09 00 00 00

string values:
0000000C  4f 4e 45 00 4e 49 4e 45  00

data string:
00000015  01 00 00 00 00 00 00 00  03 00 00 00 04 00 00 00

key/value 1 (key = 1, string index = 0 (&quot;ONE&quot;)):
01 00 00 00  00 00 00 00

key/value 2 (key = 3, string index = 4 (&quot;NINE&quot;)):
03 00 00 00  04 00 00 00
</pre></div></div>
   </div>
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-quickhashintstringhash.loadfromfile-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">filename</code></dt>

     <dd>

      <p class="para">
       The filename of the file to read the hash from.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">size</code></dt>

     <dd>

      <p class="para">
       The amount of bucket lists to configure. The number you pass in will be
       automatically rounded up to the next power of two. It is also
       automatically limited from <code class="literal">4</code> to <code class="literal">4194304</code>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">options</code></dt>

     <dd>

      <p class="para">
       The same options that the class&#039; constructor takes; except that the size
       option is ignored. It is automatically calculated to be the same as the
       number of entries in the hash, rounded up to the nearest power of two
       with a maximum limit of <code class="literal">4194304</code>.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-quickhashintstringhash.loadfromfile-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns a new <span class="classname"><a href="class.quickhashintstringhash.html" class="classname">QuickHashIntStringHash</a></span>.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-quickhashintstringhash.loadfromfile-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5139">
    <p><strong>示例 #3 <span class="function"><strong>QuickHashIntStringHash::loadFromFile()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$file&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dirname</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">__FILE__&nbsp;</span><span style="color: #007700">)&nbsp;.&nbsp;</span><span style="color: #DD0000">"/simple.string.hash"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$hash&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">QuickHashIntStringHash</span><span style="color: #007700">::</span><span style="color: #0000BB">loadFromFile</span><span style="color: #007700">(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$file</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">QuickHashIntStringHash</span><span style="color: #007700">::</span><span style="color: #0000BB">DO_NOT_USE_ZEND_ALLOC<br /></span><span style="color: #007700">);<br />foreach(&nbsp;</span><span style="color: #0000BB">range</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0x0f&nbsp;</span><span style="color: #007700">)&nbsp;as&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">printf</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">"Key&nbsp;%3d&nbsp;(%2x)&nbsp;is&nbsp;%s\n"</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$hash</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">exists</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$key&nbsp;</span><span style="color: #007700">)&nbsp;?&nbsp;</span><span style="color: #DD0000">'set'&nbsp;</span><span style="color: #007700">:&nbsp;</span><span style="color: #DD0000">'unset'<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Key   0 ( 0) is unset
Key   1 ( 1) is set
Key   2 ( 2) is set
Key   3 ( 3) is set
Key   4 ( 4) is unset
Key   5 ( 5) is set
Key   6 ( 6) is unset
Key   7 ( 7) is set
Key   8 ( 8) is unset
Key   9 ( 9) is unset
Key  10 ( a) is unset
Key  11 ( b) is set
Key  12 ( c) is unset
Key  13 ( d) is set
Key  14 ( e) is unset
Key  15 ( f) is unset
</pre></div>
    </div>
   </div>
  </p>
 </div>



</div></div></div></body></html>